package com.mallcai.bigdata.ladon.controller.system.form;

import com.mallcai.bigdata.ladon.controller.BaseForm;
import com.mallcai.bigdata.ladon.dpl.entity.system.User;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * Created by oneape<oneape15@163.com>
 * Created 2019-06-18 17:49.
 * Modify:
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class UserForm extends BaseForm {

    @NotNull(message = "主键Id不能为空", groups = {IdCheck.class})
    private Long       userId;
    @NotBlank(message = "登录用户名不能为空", groups = {AddCheck.class, EditCheck.class})
    private String     username;
    @NotBlank(message = "用户姓名不能为空", groups = {AddCheck.class, EditCheck.class})
    private String     nickname;
    private String     password;
    @NotBlank(message = "所属部门不能为空", groups = {AddCheck.class, EditCheck.class})
    private String     department;
    private String     position;
    private String     phone;
    private String     email;
    private List<Long> roleIds; // 角色Id列表

    @NotBlank(message = "新密码不能为空", groups = {ChangePwdCheck.class})
    private String newPwd; // 新密码
    @NotBlank(message = "旧密码不能为空", groups = {ChangePwdCheck.class})
    private String oldPwd; // 旧密码


    public interface ChangePwdCheck {
    }

    public interface IdCheck {
    }

    public interface AddCheck {
    }

    public interface EditCheck {
    }

    public User toEntity() {
        User user = new User();
        user.setId(userId);
        user.setNickname(nickname);
        user.setUsername(username);
        user.setPassword(password);
        user.setDepartment(department);
        user.setPosition(position);
        user.setPhone(phone);
        user.setEmail(email);
        return user;
    }
}
